<%@ page language="java" contentType="text/html;charset=utf-8" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="zh" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="zh" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <jsp:include page="../common/common.jsp"/>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
<jsp:include page="../common/header.jsp"/>
<div class="clearfix"></div>
<div class="page-container">
    <div class="page-sidebar-wrapper">
        <jsp:include page="../common/menu.jsp"/>
    </div>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <div class="portlet box purple">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="fa fa-reorder"></i>发送站内信<span id="dis"></span>
                            </div>
                        </div>
                        <div class="portlet-body form">
                            <form id="sendMsgForm" class="form-horizontal">
                                <div class="form-body">
                                    <div class="form-group">
                                        <label class="col-md-2 control-label">辐射范围</label>
                                        <div class="col-md-9">
                                            <div class="clearfix">
                                                <div class="btn-group" data-toggle="buttons">
                                                    <label class="btn blue">
                                                        <input type="radio" class="toggle" name="type" value="a"> 所有用户 </label>
                                                    <label class="btn blue active">
                                                        <input type="radio" class="toggle" name="type" value="p"> 个人用户 </label>
                                                    <label class="btn blue">
                                                        <input type="radio" class="toggle" name="type" value="e"> 企业用户 </label>
                                                    <label class="btn blue">
                                                        <input type="radio" class="toggle" name="type" value="n"> 指定用户 </label>
                                                    <label>
                                                        <input type="hidden" id="userId" name="userid" value="${userId}"/>
                                                        <input type="text" class="form-control" id="user" name="username" value="${userName}" style="display: none"/>
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">标题</label>
                                        <div class="col-md-8">
                                            <input type="text" class="form-control" datatype="*1-10" name="title"/>
                                        </div>
                                        <div class="col-md-2">
                                            &nbsp;可输入<b><span>10</span></b> 个字符
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">信息内容</label>
                                        <div class="col-md-8">
                                            <textarea id="context" name="context" datatype="*1-230" class="form-control"
                                                      maxlength="225" rows="3" placeholder="请填写信息内容..."></textarea>
                                        </div>
                                        <div class="col-md-2">
                                            &nbsp;可输入<b><span>230</span></b> 个字符
                                        </div>
                                    </div>
                                </div>
                                <div class="form-actions right">
                                    <%--<button type="button" class="btn default" id="btnCancel">取消</button>--%>
                                    <button type="button" class="btn green" id="btnSubmit">提交</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../common/footer.jsp"/>
<script type="text/javascript">
    var form;
    $(function () {
        if('${userId}') {
            $(":radio[value='n']").click();
            $("#user").show();
        }
        form = $("#sendMsgForm").Validform({
            tiptype: 3,
            postonce: true,
            showAllError: true,
            callback: function (data) {
                if (data) {
                    switch (data.statusCode) {
                        case 200:
                            window.location.href = _path + "/info/list?s=1";
                            break;
                        case 201:
                            App.bubble(500, "信息内容不能为空！");
                            break;
                        case 202:
                            App.bubble(500, "没有查询到接受用户！");
                            break;
                        case 500:
                            App.bubble(500, "消息发送失败！");
                            break;
                        default:
                            App.bubble(500, "消息发送失败！");
                            break;
                    }
                }
            }
        });
        $(":radio").change(function() {
            if("n"===$(this).val()) $("#user").show().focus();
            else $("#user").hide();
        })
        $("#btnSubmit").click(function () {
            form.ajaxPost(false, true, _path + "/info/save");
        });
    });
</script>
</body>
</html>